<template>
  <div class="clearfix">
    <div class="clear hei40"></div>
    <div class="con-width-1200 content">
      <div class="public-title clearfix pos-rel">
        <h2 class="pos-rel course">Search</h2>
        <h1 class="pos-abs">全文检索</h1>
        <!-- <h3 class="pos-abs">{{ date1.title }}</h3> -->
        <div class="catage clearfix pos-abs">您所在位置： >
          <label>全文检索</label>
        </div>
      </div>
      <h1>{{notFind}}</h1>
      <ul class="article-list rad5 clearfix">
        <li
          class="clearfix pos-rel"
          v-for="(item, index) in date1.records"
          :key="index"
          @click="jump(item.id)"
        >
          <h1 class="text-wid" v-html="item.title"></h1>
          <span class="intro">{{ item.description }}</span>
          <span class="data pos-abs">{{ item.releaseDate }}</span>
        </li>
      </ul>
    </div>
    <div class="page-list clearfix">
      <template v-for="count in date1.pages">
        <a
          @click="pagination($event, count)"
          :class="count == date1.current ? 'focus' : ''"
          :key="count"
        >{{ count }}</a>
      </template>
    </div>
    <div class="clear hei20"></div>
  </div>
</template>

<script>
import _http from "../httpService";

export default {
  name: "HospitalSummedup",
  props: {
    msg: String,
  },
  components: {},
  data() {
    return {
      notFind: "",
      pageNo: 1,
      pageSize: 10,
      date1: {
        ipage: {},
        channelName: "",
        channelNameEn: "",
        channelContent: "",
      },
      dataList: [],
      isDisable: false,
      name: "",
      mobile: "",
      content: "",
    };
  },
  methods: {
    jump: function(id) {
      this.$router.push({ path: "/Article/" + id });
    },

    pagination: function(e, pageNo) {
      this.pageNo = pageNo;
      console.log(this.$route.query);
      _http
        .get(
          "/content/jcContent/fullTextSearch?channelname=" +
            this.$route.query.keyWord +
            "&pageNo=" +
            pageNo +
            "&pageSize=" +
            this.pageSize
        )
        .then((resp) => {
          if (resp.data.success) {
            this.date1 = resp.data.result;
          }
        })
        .catch((error) => console.log(error))
        .finally(() => (this.loading = false));
    },
  },

  watch: {
    //监听相同路由下参数变化的时候，从而实现异步刷新
    $route() {
      console.log(this.$route.query);
      _http
        .get(
          "/content/jcContent/fullTextSearch?channelname=" +
            this.$route.query.keyWord +
            "&pageNo=" +
            this.pageNo +
            "&pageSize=" +
            this.pageSize
        )
        .then((resp) => {
          if (resp.data.success) {
            console.log(resp.data);
            /*for (var i = 0; i < resp.data.result.records.length; i++) {
              let replaceReg = new RegExp(this.$route.query.keyWord, "g"); // 匹配关键字正则
              let replaceString =
                '<span class="highlights-text">' +
                this.$route.query.keyWord +
                "</span>"; // 高亮替换v-html值
              resp.data.result.records[i].title = resp.data.result.records[
                i
              ].title.replace(replaceReg, replaceString); // 开始替换
            }*/
            if(resp.data.result.total == 0) {
              this.notFind = "没有找到搜索的内容"
              this.date1 = []
            }
            else {
              this.date1 = resp.data.result;
              this.notFind = "";
            }
          }
        })
        .catch((error) => console.log(error))
        .finally(() => (this.loading = false));
    },
    immediate: true,
  },
};
</script>
<style lang="scss" scoped>
@import "../assets/css/public.css";
@import "../assets/css/public.scss";
</style>
